package _2022.day._013_1184_公交站间的距离;

/**
 * @author： YHSimon
 * @date： 2022-07-24 23:37
 */
public class Solution {
    public int distanceBetweenBusStops(int[] distance, int start, int destination) {
        int res=Integer.MAX_VALUE;
        int sum=0;
        for (int value : distance) {
            sum += value;
        }
        int tmp=0;
        if(start<=destination){
            for(int i=start;i<destination;i++){
                tmp+=distance[i];
            }

        }else{
            for(int i=start;i>destination;i--) {
                tmp += distance[i];
            }
        }
        res=Math.min(res,tmp);
        res=Math.min(res,sum-tmp);
        return res;
    }

    public static void main(String[] args) {

    }
}
